package acwing.算法题;

import java.util.*;

/**
 * @author： li
 * @date： 2022-04-07 15:55
 * @version 1.0
 */
//找出下一个比它大的数
public class 单调栈 {
    static Stack<Integer> stack = new Stack<>();
    static ArrayDeque<Integer> arrayDeque = new ArrayDeque<>();//双端队列
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n =sc.nextInt();
        int[] h = new int[n+1];
        int[] a = new int[n+1];
        Arrays.fill(a,-1);
        for(int i=1;i<=n;i++)
            h[i]=sc.nextInt();
        for(int i=1;i<=n;i++){
            while(!arrayDeque.isEmpty()&&h[arrayDeque.peek()]<=h[i])
                a[arrayDeque.pop()]=h[i];
            arrayDeque.offer(i);
        }
        System.out.println(Arrays.toString(a));
    }
}
